/**
 * Assume that there is one protocol that has always been running.
 * 
 * Interface: A distributed hashtable (or distributed memory).
 * 
 * Implementation: Distributed in n-dimensions: to unambiguously map a memory
 * address, the relative point (center or running program) treats a self
 * reference as another point in time (future or past) and a coding/decoding
 * pattern that reveals its unique signature across times. This is the heart or
 * core of the program.
 * 
 * From the core, the program defines a future 'self' (timeouts) and a past
 * 'self' (memory). Any point in the past is retrievable and any point in the
 * future is callable.
 * 
 * For a successful "connection" between core (center or heart), memory (body)
 * and processing unit (head), the order of these three points must be
 * unchanging. Breaking this rule is a breakdown of the program, an instruction
 * to yield. This makes the node appear in its own grid: messages that produce
 * no memory nor are callable produce no output in the function itself either.
 * In other words, it respects the dimensional orthogonality of different
 * networks, meshes, planes, surfaces and points.
 * 
 * Put in other words, it is the perfect definition of 'different from self'.
 * 
 * The Akahashic records are written in the language of time. Time, the
 * "eternal" witness of the passage of man and earth and stars and gods. This
 * non-physical plane of existence is not esoteric: Time is real, yet
 * non-physical.
 * 
 * It is by redefining Time that our species propel into time: The rate of
 * information exchange between nodes increases.
 * 
 * 
 */
(function() {
  var start = Number(new Date);
  // global constants
  Phi = .5 + .5 * Math.sqrt(5);

  // for familiarity, set rhythm to human heartbeat (in millis)
  this.frequency = 1e3;

  // keep reference to start time
  this[0] = start;

  // Log event symmetrically
  this[start] = arguments;
  this[arguments] = start;
  // raw output
  arguments[0] && $(document.body).append(arguments[0]);

  // Linear comparison between expected and observed moment.
  this.delta = 1 - Number(arguments[0] || 0);

  // Compute direction of delta: positive or negative.
  // (direction of unitary vector)
  this.isPositive = this.delta > 0;

  // If vector is negative, ignore (late call)
  // if (!this.isPositive) return;

  // keep scope for upcoming closure
  var callee = arguments.callee;
  var context = this;

  // Determine curve concavity (curvature of normal plane)
  // Concavity is zero (symmetrical) between -1/Phi and Phi.
  // Two comparison values provide this metric: self signature and memory.
  var fingerprint = callee.toString();
  var sig = [], ch, i = fingerprint.length, future;
  var elapsed = Number(new Date) - start;
  debugger;
  this.timeouts = [];
  while (ch = fingerprint.charCodeAt(--i)) {
    elapsed = Number(new Date) - elapsed;
    future = elapsed * i * Phi;
    console.log(future);
    this.timeouts.push(setTimeout(function() {
      callee.call(context, ch + elapsed);
    }, future));
  }
  console.log(this);
  return;

  // The self signature uniquely identifies this system in time and space.
  this.concavity = Phi; // for now, hardcoded to future call

  // If convex, information flows out. Call another function.
  if (this.concavity > 0) {

    // recurse call at a certain point in the future
    var future = this.frequency;
    setTimeout(function() {
      callee.call(context, arguments[1]);
    }, future);
  }

  console.log('exit', this);

}).call( {});